#ifndef QTWORLD_H
#define QTWORLD_H

#include <QGraphicsScene>
#include <QGraphicsSceneMouseEvent>
#include <QKeyEvent>
#include "QtRobot.h"
#include "QtSpinner.h"
#include "QtTreadmill.h"
#include "QtRepairPoint.h"
#include "QtCheckPoint.h"
#include "QtWall.h"
#include "QtPusher.h"
#include "QtLaser.h"
#include "GameCommandLog.h"
#include "GroupGameCommand.h"
#include "QtPixmapSprite.h"
#include "Direction.h"
#include "QtTileManager.h"

class QtWorld: public QGraphicsScene
{
	Q_OBJECT

public:
	QtWorld(QObject *parent = 0);
	~QtWorld();

	Treadmill* CreateTreadmill(const Direction& direction, unsigned int cellx, unsigned int celly);
	Spinner* CreateSpinner(const Direction& direction, unsigned int cellx, unsigned int celly);
	RepairPoint* CreateRepairPoint(unsigned int cellx, unsigned int celly);
	CheckPoint* CreateCheckPoint(unsigned int cellx, unsigned int celly);
	Wall* CreateWall(const Direction& direction, unsigned int cellx, unsigned int celly);
	Pusher* CreatePusher(const Direction& direction, unsigned int cellx, unsigned int celly);
	Laser* CreateLaser(const Direction& direction, unsigned int cellx, unsigned int celly);
	Robot* CreateRobot(const std::string& type, unsigned int cellx, unsigned int celly);

	void Play(bool dropfirst);

	void mousePressEvent(QGraphicsSceneMouseEvent *e);
	void keyPressEvent(QKeyEvent *e);
private slots:
	void OnAnimationFinished();
	void OnAnimationStarted();
private:
	void BeginCommand();
	void EndCommand();
	void RobotMove(Robot* robot, const Direction& direction);
	void RobotTurn(Robot* robot, const Direction& direction);
	void RobotSpawn(Robot* robot);
	void RobotFall(Robot* robot);
	void RobotHit(Robot* robot);
	void RobotShoot(Robot* robot);
	void TreadmillActivate(Treadmill* treadmill);
	void SpinnerActivate(Spinner* spinner);
	void CheckPointActivate(CheckPoint* checkpoint);
	void RepairPointActivate(RepairPoint* repairpoint);
	void PusherActivate(Pusher* pusher);
	void LaserActivate(Laser* laser, const bool& enabled);
	
	bool animated;
	QtRobot *robot2;
    QtRobot *robot1;
	QtTreadmill *treadmill1;
	QtTreadmill *treadmill2;
	QtSpinner *spinner1;
	QtSpinner *spinner2;
	QtRepairPoint *repair1;
	QtCheckPoint *check1;
	QtWall *wall1;
	QtWall *wall2;
	QtWall *wall3;
	QtWall *wall4;
	QtPusher *pusher1;
	QtLaser *laser1;
	GameCommandLog log;

	GroupGameCommand commandGroup;

	int animations;
	unsigned int cellSize;

	QtTileManager tileManager;
};

#endif //QTWORLD_H